package main

import (
	"errors"
	"flag"
	"fmt"
	"strings"
)

var LenErr = errors.New("长度错误")
type Str struct {
	Cmd string
}
type loginStr struct {
	Str
	name string
	pwd string
}
type registerStr struct {
	Str
	loginStr
	sex string
}
type msgStr struct {
	Str
	to string
	msg string
}
func (l *Str)String() string {
	return fmt.Sprintf("%v",*l)
}

func (l *loginStr)Set(s string)error{
	v:=strings.Split(s,":")
	if len(v)<1{
		return LenErr
	}
	l.name=v[0]
	l.pwd=v[1]
	return nil
}

func (l *registerStr)Set(s string)error{
	v:=strings.Split(s,":")
	if len(v)<2{
		return LenErr
	}
	l.name=v[0]
	l.pwd=v[1]
	l.sex=v[2]
	return nil
}
func (l *msgStr)Set(s string)error{
	v:=strings.IndexByte(s,':')
	if v<0{
		return LenErr
	}
	s2:=strings.SplitN(s,":",2)
	l.to=s2[0]
	l.msg=s2[1]
	return nil
}


var login loginStr
var register registerStr
var msg msgStr

var list bool

func flagStart()  {
	flag.Var(&login, "login", "请输入：-login=用户名:密码")
	flag.Var(&register, "register", "请输入：-register=用户名:密码:性别")
	flag.Var(&msg, "msg", "请输入：-msg=用户名:内容")
	flag.BoolVar(&list,"list",false,"-list=true 用户列表")
}
